// 图片懒加载 https://github.com/hilongjw/vue-lazyload
import VueLazyload from 'vue-lazyload'
// 过滤器 https://github.com/freearhey/vue2-filters
import Vue2Filters from 'vue2-filters'
// 一个更好的moment https://github.com/julon/vue-moment-lib
import VueMomentLib from 'vue-moment-lib'
// 有赞vant https://www.youzanyun.com/zanui/vant#/zh-CN/intro
import Vant from 'vant'
import 'vant/lib/vant-css/index.css'

// zui组件
import ZContainer from './z-container'
import ZHeader from './z-header'
import ZMain from './z-main'
import ZAside from './z-aside'
import ZFooter from './z-footer'
import ZImage from './z-image'
import ZTheme from './z-theme'
import ZIcon from './z-icon'

const components = [
  ZContainer,
  ZHeader,
  ZMain,
  ZAside,
  ZFooter,
  ZImage,
  ZTheme,
  ZIcon
]

const install = function (Vue) {
  if (install.installed) return
  Vue.use(VueLazyload, {
    lazyComponent: true
  })
  Vue.use(Vue2Filters)
  Vue.use(VueMomentLib)
  Vue.use(Vant)
  components.map(component => {
    Vue.component(component.name, component)
  })
}

// auto install
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

export default {
  install
}
